package cn.zyq.ykb.controller.h5.task;

import cn.zyq.ykb.beans.config.ConfigProp;
import cn.zyq.ykb.beans.config.ConfigTaskType;
import cn.zyq.ykb.beans.task.Task;
import cn.zyq.ykb.beans.task.bo.*;
import cn.zyq.ykb.beans.task.dto.ClaimTaskDto;
import cn.zyq.ykb.service.task.TaskService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 任务Controller
 *
 * @author SystemAuth
 * @date 2023-05-22
 */

@RestController(value = "H5TaskController")
@RequestMapping("/api/task")
@Api(tags = "任务接口")
public class TaskController extends BaseController {

    @Autowired
    private TaskService taskService;

    /**
     * 查询任务列表
     */
    @ApiOperation(value = "首页列表/简单任务", response = Task.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.taskService.selectTaskList(pageParam , this.getLoginUser());
    }

    /**
     * 悬赏赚任务赚统计
     */
    @ApiOperation(value = "悬赏赚任务赚统计", response = Task.class)
    @GetMapping("/total/{state}/{taskPackageID}")
    public Object total(@PathVariable("state") Integer state,@PathVariable("taskPackageID") Integer taskPackageID) {
        return this.taskService.selectTotal(state,taskPackageID,this.getLoginUser());
    }

    /**
     * 获取任务详细信息
     */
    @ApiOperation(value = "任务详情", response = Task.class)
    @GetMapping(value = "/{taskID}/{type}")
    public Object getInfo(@PathVariable("taskID") Integer taskID,@PathVariable("type") Integer type) {
        return this.taskService.selectTaskByTaskID(taskID,type, this.getLoginUser());
    }

    /**
     * 新增任务
     */
    @ApiOperation(value = "新增任务")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody TaskAddBo bo) {
        return this.taskService.insertTask(bo,this.getLoginUser());
    }

    /**
     * 修改任务
     */
    @ApiOperation(value = "编辑任务步骤")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody TaskUptBo bo) {
        return this.taskService.updateTask(bo,this.getLoginUser());
    }

    /**
     * 领取任务
     */
    @ApiOperation(value = "领取任务")
    @GetMapping("/neckTask/{taskID}/{type}")
    public Object neckTask(@PathVariable("taskID") Integer taskID,@PathVariable("type") Integer type) {
        return this.taskService.neckTask(taskID,type,this.getLoginUser());
    }

    /**
     * 提交任务
     */
    @ApiOperation(value = "提交任务")
    @PostMapping("/claimTask")
    public Object claimTask(@RequestBody ClaimTaskDto dto) {
        return this.taskService.claimTask(dto,this.getLoginUser());
    }

    /**
     * 任务包列表
     */
    @ApiOperation(value = "任务包列表统计")
    @PostMapping("/taskPackage")
    public Object taskPackage() {
        return this.taskService.taskPackage();
    }

    /**
     * 任务赚列表
     */
    @ApiOperation(value = "任务赚列表", response = Task.class)
    @PostMapping("/packageList")
    public Object packageList(@RequestBody PageParam pageParam) {
        return this.taskService.packageList(pageParam);
    }

    /**
     * 查询任务列表
     */
    @ApiOperation(value = "悬赏赚列表", response = Task.class)
    @PostMapping("/rewardList")
    public Object rewardList(@RequestBody PageParam pageParam) {
        return this.taskService.rewardList(pageParam);
    }

    /**
     * 我的发布列表
     */
    @ApiOperation(value = "我的发布列表", response = Task.class)
    @PostMapping("/publishing")
    public Object publishing(@RequestBody PageParam pageParam) {
        return this.taskService.publishing(pageParam,this.getLoginUser());
    }

    /**
     * 我的发布详情
     */
    @ApiOperation(value = "我的发布详情", response = Task.class)
    @GetMapping("/publishingDetail/{taskID}")
    public Object publishingDetail(@PathVariable("taskID") Integer taskID) {
        return this.taskService.publishingDetail(taskID);
    }

    /**
     * 开始任务
     */
    @ApiOperation(value = "开始任务", response = Task.class)
    @PostMapping("/upTask")
    public Object upTask(@RequestBody Task task) {
        return this.taskService.upTask(task,this.getLoginUser());
    }

    /**
     * 暂停任务
     */
    @ApiOperation(value = "暂停任务", response = Task.class)
    @PostMapping("/downTask")
    public Object downTask(@RequestBody Task task) {
        return this.taskService.downTask(task,this.getLoginUser());
    }

    /**
     * 修改任务/修改价格详情
     */
    @ApiOperation(value = "修改任务/修改价格详情")
    @GetMapping("/getUptTask/{taskID}")
    public Object getUptTask(@PathVariable("taskID") Integer  taskID) {
        return this.taskService.getUptTask(taskID,this.getLoginUser());
    }

    /**
     * 修改价格
     */
    @ApiOperation(value = "修改价格")
    @PostMapping("/uptPrice")
    public Object uptPrice(@RequestBody UptPriceBo bo) {
        return this.taskService.uptPrice(bo,this.getLoginUser());
    }

    /**
     * 修改数量
     */
    @ApiOperation(value = "修改数量")
    @PostMapping("/uptNumber")
    public Object uptNumber(@RequestBody UptNumberBo bo) {
        return this.taskService.uptNumber(bo,this.getLoginUser());
    }

    /**
     * 任务包列表
     */
    @ApiOperation(value = "首页统计")
    @PostMapping("/statistics")
    public Object statistics(@RequestBody ConfigTaskType configTaskType) {
        return this.taskService.statistics(configTaskType,this.getLoginUser());
    }


    /**
     * 屏蔽项目列表
     */
    @ApiOperation(value = "屏蔽项目列表", response = Task.class)
    @PostMapping("/getList")
    public Object getList(@RequestBody PageParam pageParam) {
        return this.taskService.getList(pageParam,this.getLoginUser());
    }

    /**
     * 修改任务/修改价格详情
     */
    @ApiOperation(value = "屏蔽任务/恢复任务")
    @GetMapping("/shield/{taskIDs}")
    public Object shield(@PathVariable Integer[]  taskIDs) {
        return this.taskService.shield(taskIDs,this.getLoginUser());
    }

    /**
     * 推广订单列表
     */
    @ApiOperation(value = "推广订单列表", response = Task.class)
    @PostMapping("/getPromotionList")
    public Object getPromotionList(@RequestBody PageParam pageParam) {
        return this.taskService.getPromotionList(pageParam,this.getLoginUser());
    }

    /**
     * 查询任务列表
     */
    @ApiOperation(value = "推广列表统计", response = Task.class)
    @GetMapping("/tgTotal")
    public Object tgTotal() {
        return this.taskService.tgTotal(this.getLoginUser());
    }

    /**
     * 推广订单详情
     */
    @ApiOperation(value = "推广订单详情", response = Task.class)
    @GetMapping("/tgDetail/{myTaskID}")
    public Object tgDetail(@PathVariable("myTaskID") Integer myTaskID) {
        return this.taskService.tgDetail(myTaskID);
    }

    /**
     * 任务下单
     */
    @ApiOperation(value = "任务下单", response = ConfigProp.class)
    @PostMapping("/taskOrder")
    public Object taskOrder(@RequestBody Task pageParam) {
        return this.taskService.taskOrder(pageParam,this.request, this.getLoginUser());
    }

//    /**
//     * 直接提交
//     */
//    @ApiOperation(value = "直接提交")
//    @PostMapping("/claim")
//    public Object claim(@RequestBody ClaimTaskDto dto) {
//        return this.taskService.claim(dto,this.getLoginUser());
//    }

    /**
     * 任务列表
     */
    @ApiOperation(value = "任务列表", response = Task.class)
    @PostMapping("/taskListAll")
    public Object taskListAll(@RequestBody PageParam pageParam) {
        return this.taskService.taskListAll(pageParam);
    }

    /**
     * 任务列表
     */
    @ApiOperation(value = "任务列表统计", response = Task.class)
    @GetMapping("/taskListTotal/{state}")
    public Object taskListTotal(@PathVariable("state") Integer state) {
        return this.taskService.taskListTotal(state,this.getLoginUser());
    }

    /**
     * 任务调价
     */
    @ApiOperation(value = "任务调价", response = Task.class)
    @PostMapping("/uptTaskPrice")
    public Object uptTaskPrice(@RequestBody UptTaskPriceBo bo) {
        return this.taskService.uptTaskPrice(bo,this.getLoginUser());
    }


}
